package com.two.service.collect.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.two.common.entity.Collect;
import com.two.common.entity.Menu;
import com.two.common.entity.Tuimoney;
import com.two.common.util.CommonResult;
import com.two.service.collect.feign.CaiPinFeign;
import com.two.service.collect.mapper.CollectMapper;
import com.two.service.collect.mapper.TuiMapper;
import com.two.service.collect.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;


@Service
public class CollectServiceImpl implements CollectService {

    @Autowired
    private CollectMapper collectMapper;

    @Autowired
    private TuiMapper tuiMapper;



    // 添加收藏
    @Override
    public int insertAll(Collect collect) {
        QueryWrapper<Collect> wrapper = new QueryWrapper<>();
        List<Collect> collects = collectMapper.selectList(wrapper);
        for (Collect collect1 : collects) {
            if (collect.getMid()==collect1.getMid()){
                return 0;
            }
        }
        return collectMapper.insert(collect);
    }

    @Override
    public Integer delectCollect(Integer mid) {
        QueryWrapper<Collect> wrapper = new QueryWrapper<>();
        wrapper.eq("mid",mid);
        int delete = collectMapper.delete(wrapper);
        return delete;
    }

    @Override
    public CommonResult selectAll(String usermonicker) {
        QueryWrapper<Tuimoney> wrapper = new QueryWrapper<>();
        wrapper.eq("usermonicker",usermonicker);
        List<Tuimoney> tuimonies = tuiMapper.selectList(wrapper);
        return new CommonResult(2000,"查询成功",tuimonies);

    }


}
